package basic;

public class Attribute {

	/** The name of attribute. */
	private String name = "";

	/** The type of attribute */
	private String type = "";

	/** The number of elements that compose attribute */
	private String num = "";

	/** This class' property indicate if the attribute is null or not. */
	private boolean Null = false;

	/** The default value */
	private String def = "";

	/** The auto_increment */
	private boolean auto_incr = false;

	/** The Constant dataType. */
	public static final String[] dataType = new String[] { "tinyint",
		"smallint", "mediumint", "int", "bigint", "float", "double",
		"decimal", "bit", "char", "varchar", "tinytext", "text",
		"mediumtext", "longtext", "binary", "varbinary", "tinyblob",
		"blob", "mediumblob", "longblob", "enum", "set", "date",
		"datetime", "timestamp", "year", "time" };

	/** The draw_h_cardinality. */
	private int draw_h_cardinality = -1; // (0: o2o, 1: o2all, 2: all2o, 3:
	// all2all)

	/**
	 * Instantiates a new attribute.
	 * 
	 * @param name
	 *            the name
	 * @param type
	 *            the type
	 * @param num
	 *            the num
	 * @param Null
	 *            the null
	 * @param def
	 *            the def
	 * @param auto_incr
	 *            the auto_incr
	 */
	public Attribute(String name, String type, String num, boolean Null,
			String def, boolean auto_incr) {
		this.name = name;
		this.type = type;
		this.num = num;
		this.def = def;
		this.Null = Null;
		this.auto_incr = auto_incr;
	}

	/**
	 * Instantiates a new attribute.
	 * 
	 * @param name
	 *            the name
	 */
	public Attribute(String name) {
		this.name = name;
	}

	/**
	 * Returns length of attributes for svg drawing.
	 * 
	 * @param type
	 *            the type
	 * @return attribute's name length unused
	 */
	public int getCompleteSizaAttribute(boolean type) {
		int attrlength = this.name.length() + 2;
		if (this.getDefault() != "null" || this.getDefault() != "") {
			String tempstring = "Default " + this.getDefault();
			attrlength += tempstring.length();
		}
		if (this.getDefault() == "null" || this.getDefault() == "")
			attrlength += 4;
		else
			attrlength += 8;

		if (this.getNum() != "")
			attrlength += this.getNum().length() + 2;

		if (!type) {
			if (this.getType() != "")
				attrlength += this.getType().length();
		}

		if (this.getAutoIncr() == true)
			attrlength += 15;

		return attrlength;

	}

	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * Gets the type.
	 * 
	 * @return the type
	 */
	public String getType() {
		return this.type;
	}

	/**
	 * Gets the default.
	 * 
	 * @return the default
	 */
	public String getDefault() {
		return this.def;
	}

	/**
	 * Sets the type.
	 * 
	 * @param str
	 *            the new type
	 */
	public void setType(String str) {
		this.type = str;
	}

	/**
	 * Sets the default.
	 * 
	 * @param str
	 *            the new default
	 */
	public void setDefault(String str) {
		this.def = str;
	}

	/**
	 * Gets the num.
	 * 
	 * @return the num
	 */
	public String getNum() {
		return this.num;
	}

	/**
	 * Sets the num.
	 * 
	 * @param num
	 *            the new num
	 */
	public void setNum(String num) {
		this.num = num;
	}

	/**
	 * setter and getter methods for auto increment property.
	 * 
	 * @param auto
	 *            the new auto incr
	 */
	public void setAutoIncr(boolean auto) {
		this.auto_incr = auto;
	}

	/**
	 * Gets the auto incr.
	 * 
	 * @return the auto incr
	 */
	public boolean getAutoIncr() {
		return this.auto_incr;
	}

	/**
	 * setter and getter methods for null property.
	 * 
	 * @param Null
	 *            the new null
	 */
	public void setNull(boolean Null) {
		this.Null = Null;
	}

	/**
	 * Gets the null.
	 * 
	 * @return the null
	 */
	public boolean getNull() {
		return this.Null;
	}

	/**
	 * Checks if is numeric attribute.
	 * 
	 * @return true, if is numeric attribute
	 */
	public boolean isNumericAttribute() {
		if (type.compareTo("int") == 0 && type.compareTo("mediumint") == 0
				&& type.compareTo("bigint") == 0
				&& type.compareTo("tinyint") == 0
				&& type.compareTo("smallint") == 0)
			return false;
		else
			return true;
	}

	/**
	 * Gets the draw h cardinality.
	 * 
	 * @return the draw h cardinality
	 */
	public int getDrawHCardinality() {
		return this.draw_h_cardinality;
	}

	/**
	 * Sets the draw h cardinality.
	 * 
	 * @param ncard
	 *            the new draw h cardinality
	 */
	public void setDrawHCardinality(int ncard) {
		this.draw_h_cardinality = ncard;
	}
}
